<!DOCTYPE html>
<html>

<body>
	<script src="/bower_components/jquery/dist/jquery.min.js"></script>
	<script src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
	<script src="/dist/js/adminlte.min.js"></script>
	<script src="/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
	<script src="/bower_components/moment/min/moment.min.js"></script>
	<script src="/bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
	<script src="/js/formValid.js"></script>
	<script src="/js/jquery.validate.min.js"></script>
	<script src="/plugins/layx/layx.min.js"></script>

	<script type="text/javascript">
		$(function () {
			$.extend($.validator.messages, {
				required: "必选字段",
				remote: "请修正该字段",
				email: "请输入正确格式的电子邮件",
				url: "请输入合法的网址",
				date: "请输入合法的日期",
				dateISO: "请输入合法的日期 (ISO).",
				number: "请输入合法的数字",
				digits: "只能输入整数",
				creditcard: "请输入合法的信用卡号",
				equalTo: "请再次输入相同的值",
				accept: "请输入拥有合法后缀名的字符串",
				maxlength: $.validator.format("请输入一个长度最多是 {0} 的字符串"),
				minlength: $.validator.format("请输入一个长度最少是 {0} 的字符串"),
				rangelength: $.validator.format("请输入一个长度介于 {0} 和 {1} 之间的字符串"),
				range: $.validator.format("请输入一个介于 {0} 和 {1} 之间的值"),
				max: $.validator.format("请输入一个最大为 {0} 的值"),
				min: $.validator.format("请输入一个最小为 {0} 的值")
			});

			$("#form1").validate({
				//debug : true,
				errorPlacement : function(error, element) {
					$(element).closest("div.form-group").find("label:first").after(error);
					   //$( element ).closest( "div.form-group" ).find( "label[for='" + element.attr( "name" ) + "']" ).append( error );
		        },
		        messages : {
		        	demandType : {
		        		required : "至少选择一项",
		        	},
		        	researchField : {
		        		required : "至少选择一项",
		        	}
		        }
			});
		});

		//Date picker
		$('#datepicker').datepicker({
			autoclose: true
		});

		$('#datepicker2').datepicker({
			autoclose: true
		});
		
		$('#datepicker3').datepicker({
			autoclose: true
		});
		
		$('#datepicker4').datepicker({
			autoclose: true
		});
		
		$('#datepicker5').datepicker({
			autoclose: true
		});

		$('#reservation').daterangepicker();

		//进入添加页面
		$(document).on('click', '#addPerson', function () {
			window.location.href = "/person/addView";
		})
		//进入添加页面
		$(document).on('click', '#addDictiontry', function () {
			window.location.href = "/dictiontry/addView";
		})
		
		//关注模块项目，需求，专家等等
        function subscribe(objectid,typeid){
            $.ajax({
                type : "POST",
                url : "/subscri/addSubscribe",
                async : true,
                data : {"objectType":objectid,"type":typeid,[[${_csrf.parameterName}]]:"[[${_csrf.token}]]"},
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    if (data.status) {
                        alert(data.obj);
                        var clickVal = $("a#"+objectid).attr("onclick");
                        $("a#"+objectid).attr("onclick", clickVal.replace("subscribe", "delSub"));
                        $("a#"+objectid).text("取消关注");
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
		
		//专家添加关注操作
		function subscribe1(objectid,typeid){
            $.ajax({
                type : "POST",
                url : "/subscri/addSubscribe",
                async : true,
                data : {"objectType":objectid,"type":typeid,[[${_csrf.parameterName}]]:"[[${_csrf.token}]]"},
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    if (data.status) {
                        alert(data.obj);
                        var clickVal = $("a#"+objectid).attr("onclick");
                        $("a#"+objectid).attr("onclick", clickVal.replace("subscribe1", "delSub1"));
                        $("a#"+objectid).text("取消关注");
                      	//当删除关注复选框变成不可选
                      	$("a#"+objectid).closest("tr").find("input").prop("disabled", true);
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
		
        //删除关注
        function delSub(objectid,typeid){
            $.ajax({
                type : "post",
                url : "/subscri/deleteSubscribe",
                async : true,
                data : {"objectType":objectid,"type":typeid,[[${_csrf.parameterName}]]:"[[${_csrf.token}]]"},
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    if (data.status) {
                        alert(data.obj);
                        var clickVal = $("a#"+objectid).attr("onclick");
                        $("a#"+objectid).attr("onclick", clickVal.replace("delSub", "subscribe"));
                        $("a#"+objectid).text("关注");
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
        
        //专家删除关注操作
        function delSub1(objectid,typeid){
            $.ajax({
                type : "post",
                url : "/subscri/deleteSubscribe",
                async : true,
                data : {"objectType":objectid,"type":typeid,[[${_csrf.parameterName}]]:"[[${_csrf.token}]]"},
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    if (data.status) {
                        alert(data.obj);
                        var clickVal = $("a#"+objectid).attr("onclick");
                        $("a#"+objectid).attr("onclick", clickVal.replace("delSub1", "subscribe1"));
                        $("a#"+objectid).text("关注");
                      	//当删除关注复选框变成可选
                        $("a#"+objectid).closest("tr").find("input").prop("disabled", false);                        	
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
        
        //删除关注
        function deleteSub(pid){
            $.ajax({
                type : "get",
                url : "/subscri/deleteSubscribe?subId="+pid,
                async : true,
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    if (data.status) {
                        alert(data.obj);
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
        
        function _gotoPageAjax(pageNo){
            $("ul#page li").each(function(){
                $(this).removeClass('active');
            });
            var currPageno= $("ul#page li:contains("+pageNo+")");
            currPageno.addClass('active');
            //if(pageNo!=1){
                //var oldPageno= $("ul#page li:contains("+(pageNo-1)+")");
                //oldPageno.removeClass('active');
            //}
            var nextPage= $("ul#page li a:contains('下一页')");
            nextPage.attr('href',"javascript:_gotoPageAjax("+(pageNo+1)+")")
            var result="";
            $.ajax({
                type : "get",
                url : "/subscri/showSubscribe?pageNo="+pageNo,
                async : true,
                error : function(msg) {
                    result = msg;
                },
                success : function(data) {
                    
                    if (data.status) {
                        $.each(data.obj, function (n, value) {
                            result+=" <li>";
                            result+="   <span class=\"handle ui-sortable-handle\">";
                            result+=" <i class=\"fa fa-ellipsis-v\"></i>";
                            result+="  <i class=\"fa fa-ellipsis-v\"></i>";
                            result+=" </span>";
                            result+=" <input type=\"checkbox\" value=\"\">";
                           
                           
                            if(value.subType==1){
                            	 result+=" <a href=/project/showConditionQuery?pageNo=&searchKeyword="+value.remark1+" > <span class=\"text\">"+value.remark1+" </span> </a>" ;
                                result+=" <small class=\"label label-danger\"><i class=\"fa fa-clock-o\"></i> <span>项目</span></small>";
                            }else if(value.subType==2){
                           	 result+=" <a href=/demand/showConditionQuery?pageNo=&searchKeyword="+value.remark1+" > <span class=\"text\">"+value.remark1+" </span> </a>" ;
                                 result+=" <small class=\"label label-info\"><i class=\"fa fa-clock-o\"></i> <span>需求</span></small>";
                            }else if(value.subType==3){
                           	 result+=" <a href=/customer/customerList?pageNum=1&customerName="+value.remark1+" > <span class=\"text\">"+value.remark1+" </span> </a>" ;

                            	result+=" <small class=\"label label-warning\"><i class=\"fa fa-clock-o\"></i> <span>客户</span></small>";
                            }else if(value.subType==4){
                           	 result+=" <a href=/person/findPersonList?pageNo=1&name="+value.remark1+" > <span class=\"text\">"+value.remark1+" </span> </a>" ;

                            	result+=" <small class=\"label label-success\"><i class=\"fa fa-clock-o\"></i> <span>专家</span></small>";
                            }else if(value.subType==5){
                           	 result+=" <a href=/conference/conferenceList?pageNum=1&conferenceName="+value.remark1+" > <span class=\"text\">"+value.remark1+" </span> </a>" ;

                            	result+=" <small class=\"label label-primary\"><i class=\"fa fa-clock-o\"></i> <span>会议</span></small>";
                            }
                            
                            result+="  <div class=\"tools\">";
                            result+="  <i class=\"fa fa-trash-o\"></i>";
                            result+="  </div>";
                            result+=" </li>";
                            $("#subUserList").html(result);
                        });
                    }else{
                        alert(data.obj);
                    }
                }
            });
        }
        
    	
    	$(".menuTitle2").click(function() {
    		$(this).next("div").slideToggle("normal")
    				.siblings(".menuContent:hidden").slideUp("normal");
    		$(this).toggleClass("activeTitle2");
    	});
    	function  selectAnchor(id){
			$(".menuTitle2 a").each(function(){
					if($(this).attr("id")==id){
						$(this).css("backgroundColor", "red");
						}
					else{
						$(this).css("backgroundColor", "");
						}
				});
		}
    	
    	
    	
    	jQuery(document).ready(function($){
    		var offset = 300,
    		offset_opacity = 1200,
    		scroll_top_duration = 700,
    		$back_to_top = $('.cd-top');
    		$(window).scroll(function(){
    			( $(this).scrollTop() > offset ) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
    			if( $(this).scrollTop() > offset_opacity ) { 
    				$back_to_top.addClass('cd-fade-out');
    			}
    		});
    	$back_to_top.on('click', function(event){
    		event.preventDefault();
    		$('body,html').animate({
    			scrollTop: 0 ,
    		 	}, scroll_top_duration
    		);
    	});
		});
    	
    	  $("#calendar").datepicker();
	</script>
</body>

</html>